package com.zkdcloud.service;

import com.zkdcloud.domain.Address;
import com.zkdcloud.repository.AddressDao;
import com.zkdcloud.util.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * address service
 *
 * @author zk123
 * @version 2018/5/22
 */
@Service
public class AddressService {
    /**
     * address dao
     */
    @Autowired
    private AddressDao addressDao;

    /**
     * 添加 address
     *
     * @param address address
     */
    public Address addAddress(Address address){
        address.setId(RandomUtil.getUUID());
        address.setCreateTime(System.currentTimeMillis());
        addressDao.add(address);
        return address;
    }

    /**
     * uid
     *
     * @param uid uid
     * @return list
     */
    public List<Address> getByUid(String uid){
        return addressDao.getAllByUid(uid);
    }

    /**
     * 根据id获取地址
     *
     * @param id id
     * @return address
     */
    public Address getById(String id){
        return addressDao.getById(id);
    }

    /**
     * 根据id删除
     *
     * @param id id
     */
    public void removeById(String id){
        addressDao.removeById(id);
    }

    /**
     * 根据address更新
     *
     * @param address address
     */
    public void update(Address address){
        addressDao.update(address);
    }
}

